///@file FMErrorLog.h
/// <summary>
///   
/// </summary>
/// -------------------------------------------------------------------------<BR>
/// <description>
/// <BR>
/// </description>
/// <BR>
/// Created By: ypwang <BR>
/// Creation Date: Thursday April 19, 2012 <BR>   
/// Reviewed By: <BR>
/// Review Date: <BR>
/// -------------------------------------------------------------------------<BR>
///@addtogroup Error Management Error Log
///@{
#pragma once
#include <afxstr.h>

enum eAssertLevel
{	
	eAssertLevel_Fatal=0,	
	eAssertLevel_Error,	
	eAssertLevel_Warn,
	eAssertLevel_Info,
	eAssertLevel_Debug
};

class __declspec(dllexport) CFMErrorLog
{
	enum eLogType
	{
		eTextLog=0,
		eDumpLog
	};
private:
	CFMErrorLog();

public:
	~CFMErrorLog(){};
	static CFMErrorLog* GetInstance();
	static void ReleaseInstance();
	void ReleaseAssert(bool bNotLog, CString strFile, int nLine, CString strFunction, CString strErrMsg=_T(""), int nErrorLogLevel=0);
	void ReleaseAssert(int nNotLog, CString strFile, int nLine, CString strFunction, CString strErrMsg=_T(""), int nErrorLogLevel=0);
	void ReleaseAssert(UINT nNotLog, CString strFile, int nLine, CString strFunction, CString strErrMsg=_T(""), int nErrorLogLevel=0);
	void ReleaseAssert(ULONG_PTR nNotLog, CString strFile, int nLine, CString strFunction, CString strErrMsg=_T(""), int nErrorLogLevel=0);
	void ReleaseAssert(void *nNotLog, CString strFile, int nLine, CString strFunction, CString strErrMsg/*=_T("")*/, int nErrorLogLevel/*=0*/ );
	void ReleaseAssert(const void *nNotLog, CString strFile, int nLine, CString strFunction, CString strErrMsg/*=_T("")*/, int nErrorLogLevel/*=0*/ );
	void Log(BOOL bNotLog, CString strFile, int nLine, CString strFunction, CString strErrMsg=_T(""), int nErrorLogLevel=0);
	void WriteDefaultInfo();
	static CString FMGetCurrentDirFile(int iErrorType );
	int GetLogLevel() const { return m_nAssertLevel; }
private:
	void GetAssertLevel();
	void WriteAssertAsTxt( CString strErrMsg, CString strLevel, CString strFile, int nLine, CString strFunction );
	void WriteAssertAsDump();

private:
	static CFMErrorLog* m_pInstance;
	int m_nAssertLevel;
	int m_nAssertType; //using to decide the log is text file or dump file, 0: text, 1:dump
};

#define FMLOG(msg, level) CFMErrorLog::GetInstance()->Log(FALSE, __FILE__, __LINE__, __FUNCTION__, msg, level);

#ifdef MULTIFMWIN 
#define MULTIFMLOG(msg, level) FMLOG(msg,level)
#else
#define MULTIFMLOG(msg, level) NULL
#endif 

#define FMLOG_DEFAULT_INFO() CFMErrorLog::GetInstance()->WriteDefaultInfo();

#if (defined(_DEBUG) || defined(DONOT_USE_ERROR_LOG))
#define FMASSERT_FATAL(exp)	ASSERT(exp);
#define FMASSERT_WARN(exp)	ASSERT(exp);
#define FMASSERT_MSG(exp, msg)	ASSERT(exp);
#define FMASSERT_LEVEL(exp, msg, level)	ASSERT(exp);
#else
#define FMASSERT_FATAL(exp)	if(exp==0) CFMErrorLog::GetInstance()->ReleaseAssert(exp, CString(__FILE__), __LINE__, CString(__FUNCTION__), _T(#exp), eAssertLevel_Fatal);
#define FMASSERT_WARN(exp)	if(exp==0) CFMErrorLog::GetInstance()->ReleaseAssert(exp, CString(__FILE__), __LINE__, CString(__FUNCTION__), _T(#exp), eAssertLevel_Warn);
#define FMASSERT_MSG(exp, msg) if(exp==0) CFMErrorLog::GetInstance()->ReleaseAssert(exp, CString(__FILE__), __LINE__, CString(__FUNCTION__), msg, eAssertLevel_Warn);
#define FMASSERT_LEVEL(exp, msg, level)	if(exp==0) CFMErrorLog::GetInstance()->ReleaseAssert(exp, CString(__FILE__), __LINE__, CString(__FUNCTION__), msg, level);
#endif

///@}//end of addtogroup Error Management Error Log
